package com.example.wjy.viewmodels;

import android.app.Application;
import android.content.Intent;

import com.example.room.entity.Team;
import com.example.room.repository.TeamRepository;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

/**
 * author: WangJunYan
 * package: com.example.wjy.viewmodels
 * date: 2020/6/3
 * time: 19:21
 * 用于处理MyCreateTeamFragment中的数据，例如从数据库中获取数据
 */
public class MyCreateTeamViewModel extends AndroidViewModel {

    /**
     * A list of teams from server.
     */
    //不能删
    MutableLiveData<List<Team>> teamList;

    TeamRepository repository;

    public void deleteAllTeam() {
        repository.deleteAllTeam();
    }

    public MyCreateTeamViewModel(@NonNull Application application) {
        super(application);
        repository = new TeamRepository(application);
    }

    public LiveData<List<Team>> getTeamListLive() {
        return repository.getTeams();
    }

    /**
     * getter of teamList.
     * @return The LiveData of teamList
     */
    //不能删
    public MutableLiveData<List<Team>> getTeamList() {
        if(teamList == null) {
            teamList = new MutableLiveData<>();
            getTeamListFromDatabase();
        }
        return teamList;
    }

    public void insertTeam(Team... teams) {
        repository.insertTeam(teams);
    }


    //不能删，删了就报错。。。
    public void getTeamListFromDatabase(){
        List<Team> teams = new ArrayList<>();
        getTeamList().setValue(teams);
    }

    //调准到修改小队信息的界面
    public void operate() {
        Intent intent = new Intent();
    }

}
